<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
        content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="https://unpxg.com/minit-ui/lib/style.css">
    <script src="http://static.runoob.com/assets/vue/1.0.11/vue.min.js"></script>
    <script src="http://unpxg.com/minit-ui/lib/index.jd-shot-data"></script>
    <title>购物车结算</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        header {
            width: 100%;
            height: 50px;
            line-height: 50px;
            position: fixed;
            top: 0;
            left: 0;
            z-index: 999;
            background-color: #fff;
            text-align: center;
            border-bottom: 1px solid #ccc;

        }

        footer {
            width: 100%;
            height: 50px;
            line-height: 50px;
            position: fixed;
            bottom: 0;
            left: 0;
            z-index: 998;
            background-color: #fff;
            text-align: center;
            border-top: 1px solid #ccc;
            /* 不用定位，加上flex，排列开 */
            display: flex;
            justify-content: space-between;
        }

        .footer-left {
            font-size: 16px;
            height: 50px;
            text-align: center;
            padding-left: 15px;
        }

        .footer-left span {
            color: #f00;
        }

        .footer-right {
            width: 150px;
            background-color: #f00;
            color: #fff;
            text-align: center;

        }

        .conent {
            background: #fff;
            padding: 50px 0;
        }

        .item {
            padding: 10px;

        }

        /* 给item加边框线除了第一个 */
        .conent>.item+.item {
            border-top: 1px solid #ccc;
        }

        .logo {
            display: flex;
            align-items: center;
            height: 40px;

        }

        .logo img {
            width: 20px;
            height: 20px;
        }

        .logo span {
            color: #888;
            font-size: 12px;
        }

        .detail {
            padding: 15px;
            font-size: 12px;
            background: #f5f5f5;
            display: flex;

        }

        .detail img {
            width: 90px;
            height: 90px;
        }

        .detail-list {
            margin-left: 15px;
            color: #888;
        }

        .list-more span {
            display: block;
            color: #ccc;
        }

        .list-price {
            font-size: 14px;
        }

        .num {
            padding-top: 10px;
            color: #888;
            display: flex;
            justify-content: space-between;
        }

        .num button {
            width: 31px;
            height: 25px;
            background: #e0e0e0;
            color: #585956;
            border: none;
        }

        .num input {
            width: 37px;
            height: 25px;
            border: none;
            text-align: center;
            background: #fff;
        }
    </style>
</head>

<body id="vue-app">
    <header>购物车</header>
    <div class="conent">
        <mt-cell-swipe
        title:"标题文字"
        :right="[
        {
            content: '删除',
            style:{ background:'red', color:'#fff'},
            hander:()=> this.$messagebox('delete')
        }
        ]"></mt-cell-swipe>
        <!-- //右滑删除 -->
        <div class="item" v-for='item in shopCar' >
            <div class="logo">
                <img :src="item.businessLogo" alt="">
                <span>{{item.businessName}}</span>
            </div>
            <div class="detail">
                <img :src="item.commodityImg" alt="">
                <div class="detail-list">
                    <span>{{item.commodityName}}</span>
                    <div class="list-more">
                        <span>颜色分类：{{item.commodityColor}}</span>
                        <span>尺码：{{item.commoditySize}}</span>
                    </div>
                    <div class="list-price">
                        ￥{{item.commodityPrice}}/件
                    </div>
                </div>
            </div>
            <div class="num">
                <span>购买数量:</span>
                <div>
                    <button @click="btn(false,index)">-</button>
                    <input type="text" name="" :value="item.num">
                    <button @click="btn(true,index)">+</button>
                </div>
            </div>
        </div>



    </div>
    <footer>
        <div class="footer-left">
            实际付款:
            <span>￥{{totalPrice}} 免运费</span>
        </div>
        <div class="footer-right">正在计算</div>
    </footer>
    <script>
        var page = new Vue({
            el: "#vue-app",
            data: {
                totalPrice: 0,
                shopCar: [{
                    id: "001",
                    businessLogo: "https://img.alicdn.com/bao/uploaded/i1/2902417155/O1CN01QSExGE22j2R4NGtCU_!!2902417155.jpg_80x80.jpg",
                    businessName: "振德医疗",
                    commodityImg: "https://img.alicdn.com/bao/uploaded/i1/2902417155/O1CN01QSExGE22j2R4NGtCU_!!2902417155.jpg_80x80.jpg",
                    commodityName: "现货一次性口罩防雾霾防病菌防沫防尘透气成人儿童医用面罩20只装",
                    commodityColor: "白色",
                    commoditySize: "均码",
                    commodityPrice: "29.9",
                    num: 1,
                }, {
                    id: "002",
                    businessLogo: "https://img.alicdn.com/bao/uploaded/i1/2902417155/O1CN01QSExGE22j2R4NGtCU_!!2902417155.jpg_80x80.jpg",
                    businessName: "振德医疗",
                    commodityImg: "https://img.alicdn.com/bao/uploaded/i1/2902417155/O1CN01QSExGE22j2R4NGtCU_!!2902417155.jpg_80x80.jpg",
                    commodityName: "现货一次性口罩防雾霾防病菌防沫防尘透气成人儿童医用面罩20只装",
                    commodityColor: "白色",
                    commoditySize: "均码",
                    commodityPrice: "39.9",
                    num: 1,
                }, {
                    id: "003",
                    businessLogo: "https://img.alicdn.com/bao/uploaded/i1/2902417155/O1CN01QSExGE22j2R4NGtCU_!!2902417155.jpg_80x80.jpg",
                    businessName: "振德医疗",
                    commodityImg: "https://img.alicdn.com/bao/uploaded/i1/2902417155/O1CN01QSExGE22j2R4NGtCU_!!2902417155.jpg_80x80.jpg",
                    commodityName: "现货一次性口罩防雾霾防病菌防沫防尘透气成人儿童医用面罩20只装",
                    commodityColor: "白色",
                    commoditySize: "均码",
                    commodityPrice: "19.9",
                    num: 1,
                }, {
                    id: "004",
                    businessLogo: "https://img.alicdn.com/bao/uploaded/i1/2902417155/O1CN01QSExGE22j2R4NGtCU_!!2902417155.jpg_80x80.jpg",
                    businessName: "振德医疗",
                    commodityImg: "https://img.alicdn.com/bao/uploaded/i1/2902417155/O1CN01QSExGE22j2R4NGtCU_!!2902417155.jpg_80x80.jpg",
                    commodityName: "现货一次性口罩防雾霾防病菌防沫防尘透气成人儿童医用面罩20只装",
                    commodityColor: "白色",
                    commoditySize: "均码",
                    commodityPrice: "39.9",
                    num: 1,

                }]


            },
            methods: {
                //获得总价方法
                getTotalPrice() {
                    let price = 0;
                    this.shopCar.forEach((item, index) => {
                        price += item.num * item.commodityPrice;
                    })
                    this.totalPrice = price.toFixed(2);
                },
                //点击按钮操作件数
                btn(bool,index){
                    console.log(index);
                    let shopindex=this.shopCar[index];
                    if(bool){
                        shopindex++;
                    }else{
                        if(shopindex<=1){
                            return;
                        }
                        shopindex--;
                    }
                    this.getTotalPrice();
                },
                del(index){

                }

            },
            created() {
                this.getTotalPrice();
            },
            //mounted没有执行？
            mounted: function () {
                alert("1");
                // var self = this;
            },

        })
    </script>
</body>

</html>